package com.zf.yichat.config;


import com.zf.yichat.config.quartz.job.MyTestJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class JobConfig {


    @Value("${job.repeat_login_cron}")
    private String cron;
    /**
     * 定时任务1：
     * 同步用户信息Job（任务详情）
     */
    @Bean
    public JobDetail testJobDetail(){

        JobDetail JobDetail = JobBuilder.newJob(MyTestJob.class)
                .storeDurably() //必须调用该方法，添加任务
                .build();

        return JobDetail;
    }

    @Bean
    public Trigger testTrigger(){
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cron); //配置任务频率

        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(testJobDetail())
                .withSchedule(cronScheduleBuilder) //对触发器配置任务
                .build();

        return trigger;
    }

}
